import {defineStore} from "pinia"

const useSearchHistoryStore = defineStore('searchHistoryStore', {
    state() {
        return {
            searchHistory: [],
        }
    },
    actions: {
        saveKeyWord(kw) {
            if (this.searchHistory.length >= 10) {
                this.searchHistory = this.searchHistory.slice(0, 8)
            }
            this.searchHistory.unshift(kw)
        },
        clearSearchHistory() {
            this.searchHistory = []
        }
    },
    getters: {

    },
    persist: {
        enabled: true,
        strategies: [
            {
                key: 'searchHistoryStore',
                storage: window.localStorage,
                paths: ['searchHistory']
            }
        ]
    }
})

export default useSearchHistoryStore